<template>
	<view class="content">
		<view class="topBox">
			<view class="moneyTxt">账户金额</view>
			<view class="moneyTxt">{{blance.balance}}</view>
			<view class="moneyTxt">业绩</view>
			<view class="moneyTxt">{{blance.zongyeji}}</view>
			<view class="moneyTxt">复购业绩</view>
			<view class="moneyTxt">{{blance.fgyj}}</view>
			<view style="width: 100%;overflow: hidden;">
				<button @click="seePoup=!seePoup" style="float: left;">提现</button>
				<button @click="seePoups=!seePoups" style="float: right;">转账</button>
			</view>

		</view>
		<view class="top-line item-flex ">
			<!-- <view class="changeMonth item-flex">
				<picker mode="date" :value="date" fields="month" :start="startDate" :end="endDate" @change="bindDateChange">
					<view class="uni-input">{{date}}</view>
				</picker> 
				<!-- <image mode="widthFix" src="../../static/toBottom.png"></image> 
			</view> -->

			
				<view class="sumTxt">奖金总收入:{{blance.type1}}元</view>
				<view class="sumTxt">支出:{{blance.type2}}元</view>
		</view>
		<view class="list">
			<!-- <view class="line list-title item-flex">
				<view>明细</view>
				<view>金额</view>
				<view>日期</view>
			</view> -->
			<view class="line item-flex" v-for="(item,index) in blance.log">
				<view style="text-align: left;width: 70%;">
					<view >
						{{item.note}}
					</view>
					<view style="color: #999;font-size: 28rpx;">{{item.time}}</view>
				</view>
				<view style="text-align: right;width: 30%;">
					
					<view class="item-flex flex-center">
						<view style="color:red ;" v-if="item.type==1">+{{item.number}}</view>
						<view style="color: black;" v-else>-{{item.number}}</view>
					</view>
				</view>
				
				
				
			</view>
		</view>

		<view class="marke" v-show="seePoup">
			<view class="withdraw">
				<icon @click="seePoup=false" class="cancel" type="clear" size="24" color="#ccc"></icon>
				<view class="markeTitle">提现</view>
				<view class="postformcontentlevel" >
					<view class="title">提现方式：</view>
					<uni-data-select v-model="value" :localdata="range" @change="change"
						></uni-data-select>
				</view>
				<view class="postformcontentlevel" >
					<view class="title">收款码：</view>
					<text v-if='!imgshow'>点击上传</text>
					<view class="text-sm" @tap="chooseImage" :style="{ backgroundImage: 'url(' + path + ')' }" v-if='!imgshow'>
						
					</view>
					<view class="text-sm2" @tap="chooseImage" :style="{ backgroundImage: 'url(' + path + ')' }" v-if='imgshow'>
						
					</view>
				</view>
				<input class="moneyBox" type="text" cursor-spacing="50px" :placeholder="placeholderzhanghu" :value="zhanghu"
					placeholder-class="tips" @blur="changezhanghu" />
					
				<input class="moneyBox" type="text" cursor-spacing="50px" :placeholder="placeholdername" :value="name"
					placeholder-class="tips" @blur="changename" />

				
				<input class="moneyBox" type="digit" cursor-spacing="50px" placeholder="请输入提现金额" :value="number"
					placeholder-class="tips" @blur="changenumber" />
				<!-- <view class="btnGroup item-flex flex-around">
					<button>取消</button>
				</view> -->
				<view style="line-height: 40upx;color: red;font-size: 28upx;width: 96%;padding-left: 4%;">
					提示<br>
					1、提现时间为每周六。<br>
					2、提现提交之后三个工作日内到账。<br>
					3、每人每周只能提现一次，请谨慎选择。<br>
					4、提现金额需大于100
				</view>
				<button @click="tijiao">确定</button>

			</view>
		</view>

		<view class="marke" v-show="seePoups">
			<view class="withdraw">
				<icon @click="seePoups=false" class="cancel" type="clear" size="24" color="#ccc"></icon>
				<view class="markeTitle">转账给好友</view>
				<input class="moneyBox" type="digit" cursor-spacing="50px" placeholder="请输入好友UID" :value="uid"
					placeholder-class="tips" @blur="uidsss" />
				<input class="moneyBox" type="digit" cursor-spacing="50px" placeholder="请输入转账金额" :value="number"
					placeholder-class="tips" @blur="changenumber" />
				<!-- <view class="btnGroup item-flex flex-around">
					<button>取消</button>
				</view> -->
				<button @click="tijiao2">确定</button>

			</view>
		</view>
		<uni-load-more :status="status" :content-text="contentText" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				startDate: "2021-09",
				endDate: "2021-10",
				date: "2021-10",
				seePoup: false,
				blance: '',
				userinfo: '',
				number: '',
				seePoups: false,
				uid: '',
				path: '../static/shangchuan.png',
				imgshow:false,
				value: 0,
				range: [{
						value: 0,
						text: "请选择提现方式"
					},
					{
						value: 1,
						text: "微信"
					},
					{
						value: 2,
						text: "支付宝"
					},
				],
				total: 0, //数据量
				current_page: 1, //当前页码
				last_page: 1, //总页码
				status: 'more',
				contentText: {
					contentdown: ' ',
					contentrefresh: '加载中',
					contentnomore: ''
				},
				zhanghu:'',
				name:'',
				placeholdername:"请输入提现实名",
				placeholderzhanghu:"请输入提现账户"
			}
		},
		onLoad() {
			const res = uni.getStorage({
				key: 'userInfo',
				success: (res) => {
					
					if (res.data) {
						//console.log(res.data,'ssssss')
						this.userinfo = res.data
						if (this.userinfo.member_id) {
							//this.getuseragain();
							// this. url="http://pth5.njkw668.com/#/pages/user/user?&pid="+this.userinfo.member_id
						}
					} else {
						window.location.href =
							'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx9a8339b68f86cd01&redirect_uri=http%3A%2F%2Fpth5.njkw668.com%2F%23%2Fpages%2Fpublic%2Flogin&response_type=code&scope=snsapi_userinfo&state=0#wechat_redirect';
					}
				},
				fail: (res) => {
					window.location.href =
						'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx9a8339b68f86cd01&redirect_uri=http%3A%2F%2Fpth5.njkw668.com%2F%23%2Fpages%2Fpublic%2Flogin&response_type=code&scope=snsapi_userinfo&state=0#wechat_redirect';
				}
			});
			this.getuserblance()

		},
		onReachBottom() {
			//判断是否最后一页
			if (this.current_page >= this.last_page) {
				this.status = 'noMore';
			} else {
				this.reload = false;
				console.log(this.current_page, 'sssss')
				this.current_page = this.current_page + 1; //页码+1
				
				this.status = 'loading';
				this.getuserblance()
			}
		},
		
		methods: {
			change(e) {
			      this.value=e
				  if(this.value==1){
					  this.placeholdername='请输入提现微信账户实名'
					  this.placeholderzhanghu='请输入提现微信账户'
				  }
				  if(this.value==2){
				  	 this.placeholdername='请输入提现支付宝账户实名'
				  	 this.placeholderzhanghu='请输入提现支付宝账户'
				  }
			    },
			chooseImage() {
				uni.chooseImage({
					count: 1, // 默认9
					sizeType: ['compressed'], // 可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
					success: res => {
						this.imgshow=true
						// 设置url的值，显示控件
						// this.path = res.tempFilePaths[0];
						this.imgUrl = res.tempFilePaths[0];
						uni.uploadFile({
							url: 'http://ptapi.njkw668.com/index.php/api/upload/uplods_find',
							filePath: this.imgUrl,
							name: 'file',
							formData: {
								'user': 'test'
							},
							success: uploadFileRes => {
								let img = JSON.parse(uploadFileRes.data);
console.log(img)
								this.path = img.data.image
							}
						});
					}
				});
			},
			changenumber(e) {

				this.number = e.detail.value
				//console.log(e)

			},
			changezhanghu(e) {
			
				this.zhanghu = e.detail.value
				//console.log(e)
			
			},
			changename(e) {
			
				this.name = e.detail.value
				//console.log(e)
			
			},
			uidsss(e) {
				this.uid = e.detail.value
			},
			async tijiao2() {
				if(this.number==''){
						uni.showToast({
							title: '请输入转账金额',
							icon: 'none'
						})
					return false
				}
				if(this.number<0){
					uni.showToast({
						title: '请输入正确的转账金额',
						icon: 'none'
					})
					return false
				}
				if(this.uid==''){
						uni.showToast({
							title: '请输入好友uid',
							icon: 'none'
						})
					return false
				}
				const res = await this.$myRequest({
					url: 'index.php/api/user/huzhuan',
					method: "POST",
					data: {
						"member_id": this.userinfo.member_id,
						'number': this.number,
						"uid": this.uid,
					},
				})
				if (res.status == 200) {
					uni.showToast({
						title: res.data,
						icon: 'none'
					})
					setTimeout(() => {
					    uni.reLaunch({
					    	url: '/pages/user/log'
					    })
					}, 2000)
				}
			},
			
			async tijiao() {
				
				if(this.value<1){
					uni.showToast({
						title: '请选择提现方式',
						icon: 'none'
					})
					return false
				}
				if(this.path=='../static/shangchuan.png'){
					uni.showToast({
						title: '请上传提现二维码',
						icon: 'none'
					})
					return false
				}
				if(this.name==''){
					uni.showToast({
						title: this.placeholdername,
						icon: 'none'
					})
					return false
				}
				if(this.number==''){
					uni.showToast({
						title: '请输入提现金额',
						icon: 'none'
					})
					return false
				}
				if(this.number<100){
					uni.showToast({
						title: '提现金额需大于100',
						icon: 'none'
					})
					return false
				}
				if(this.zhanghu==''){
					uni.showToast({
						title: this.placeholderzhanghu,
						icon: 'none'
					})
					return false
				}
				
				const res = await this.$myRequest({
					url: 'index.php/api/user/tixian',
					method: "POST",
					data: {
						"member_id": this.userinfo.member_id,
						'number': this.number,
						'type':this.value,
						'img':this.path,
						'name':this.name,
						'zhanghu':this.zhanghu
					},
				})
				if (res.status == 200) {
					uni.showToast({
						title: res.data,
						icon: 'none'
					})
					setTimeout(() => {
					    uni.reLaunch({
					    	url: '/pages/user/log'
					    })
					}, 2000)
				}
			},
			async getuserblance() {
				//console.log(this.userinfo,'aaaaaaaaaa')
				const res = await this.$myRequest({
					url: 'index.php/api/user/balance2',
					method: "POST",
					data: {
						"member_id": this.userinfo.member_id,
						'page': this.current_page
					},
				})
				uni.stopPullDownRefresh();
				if(this.current_page==1){
					
					this.blance = res.data
					this.blance.log = res.data.log.data
					this.total = res.data.log.total; //数据量
					// this.current_page = res.data.log.current_page; //当前页码
					this.last_page = res.data.log.last_page; //总页码
					this.status = res.data.log.total == 0 ? 'noMore' : 'more';
				}else{
					console.log(res.data.log.current_page,'1')
					this.blance.log = this.blance.log.concat(res.data.log.data); //数据 追加
					this.total = res.data.log.total; //数据量
					// this.current_page = res.data.log.current_page; //当前页码
					this.last_page = res.data.log.last_page; //总页码
					this.status = res.data.log.current_page==res.data.log.last_page ? 'noMore' : 'more';
				}
				
				
				
			}
		}
	}
</script>

<style>
	.postformcontentlevel{
		display: flex;
		height: 100rpx;
		line-height: 100rpx;
		width: 90%;
		margin: 0 auto;
	}
	.text-sm2{
		width: 70%;
		margin: 0 auto;
		height: 100rpx;
		line-height: 100rpx;
		text-align: center;
		background-repeat: no-repeat;
		background-size:100% 100%;
	}
	.text-sm{
		width: 50%;
		margin: 0 auto;
		height: 100rpx;
		line-height: 100rpx;
		text-align: center;
		background-repeat: no-repeat;
		background-size:20% ;
		background-position-x: left;
		background-position-y: center;
	}
	.item-flex {
		display: flex;
		align-items: center;
		/* height: 50rpx; */
		line-height: 60rpx;
	}

	.flex-center {
		justify-content: center;
	}

	.flex-around {
		display: flex;
		justify-content: space-around;
	}

	page {
		background: #f5f5f5;
	}

	.topBox {
		width: 100%;
		padding: 20rpx 3%;
		font-size: 32rpx;
		color: #ececec;
		background: linear-gradient(to right, #3464E3, #1A55EA);
		display: flex;
		flex-direction: column;
		justify-content: space-around;
		align-items: center;
	}

	.topBox button {
		font-size: 32rpx;
		float: left;
	}

	.moneyTxt {
		font-size: 40rpx;
		color: #fff;
		font-weight: bold;
	}

	.top-line {
		width: 100%;
		flex: 1;
		padding: 10rpx 3%;
		height: 72rpx;
		line-height: 72rpx;
	}

	.list {
		width: 100%;
		padding: 0 3%;
		background: #fff;
	}

	.list .line:last-child {
		border: none
	}

	.line {
		width: 100%;
		border-bottom: 2rpx solid #ebebeb;
		text-align: left;
	}

	.line view,
	.sumTxt view {
		width: 100%;
		text-overflow: ellipsis;
		overflow: hidden;
		white-space: nowrap;
	}

	.line image {
		width: 48rpx;
		border-radius: 50%;
		margin-right: 10rpx;
	}

	.changeMonth {
		width: 30%;
		margin-right: 10%;
		position: relative;
	}

	.changeMonth picker {
		width: 100%;
	}

	.changeMonth image {
		width: 32rpx;
		position: absolute;
		right: 0;
		top: 20rpx;
	}

	.changeIcon {
		width: 32rpx;
	}

	.sumTxt {
		width: 60%;
		font-size: 28rpx;
		color: #999;
		display: flex;
		
		    flex-direction: row;
	}

	.marke {
		width: 100%;
		height: 100%;
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;
		z-index: 990;
		background: rgba(0, 0, 0, 0.7);
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.withdraw {
		width: 80%;
		background: #fff;
		border-radius: 20rpx;
		position: relative;
	}

	.markeTitle {
		width: 100%;
		height: 88rpx;
		line-height: 88rpx;
		font-size: 32rpx;
		color: #333;
		text-align: center;
		background: #f5f5f5;
		border-radius: 20rpx 20rpx 0 0;
	}

	.moneyBox {
		width: 90%;
		height: 80rpx;
		line-height: 80rpx;
		border-bottom: 2rpx solid red;
		margin: 20rpx 5%;
		text-align: center;
		font-size: 42rpx;
		font-weight: bold;
		color: red;
	}

	.tips {
		font-size: 30rpx;
		color: #bebebe;
		text-align: center;
		font-weight: normal;
	}

	.withdraw button {
		width: 90%;
		margin: 20rpx 5%;
		margin-top: 40rpx;
		font-size: 32rpx;
		height: 88rpx;
		line-height: 88rpx;
		border: none;
		background: #007AFF;
		color: #fff;
	}

	.withdraw button::after {
		border: none;
	}

	.cancel {
		position: absolute;
		top: -20rpx;
		right: -20rpx;
		background: #fff;
		border-radius: 50%;
		z-index: 999;

	}
</style>